﻿@using Kojarskiy.Core
@{
    var siteMap = (Kojarskiy.Models.SiteMap)ViewData["SiteMap"];
    List<ContentBlock> blocks = null;
    bool showLeftPart = false;
    bool showRightPart = false;
    
    if(ViewData["PageBlocks"] != null)
    {
        blocks = ContentBlock.ParseLayout(ViewData["PageBlocks"].ToString());
        foreach (var contentBlock in blocks)
        {
            if(contentBlock.Column == 1) {showLeftPart = true;}
            if(contentBlock.Column == 5) {showRightPart = true;}
        }
    }   
}

@Html.ActionLink("Главная", "Index", "Home") | @siteMap.PageName
<div style="clear: both;"></div>

@if (User.IsInRole("Administrators"))
{
<div class="form-group f_r">
    <button type="button" onclick="location.href='@Url.Action("Create", "News")'" class="btn btn-sm btn-success">Добавить новость</button>
    <button type="button" onclick="location.href='@Url.Action("Edit", "SiteMap", new { id = siteMap.SiteMapId, returnUrl = Request.RawUrl })'" class="btn btn-sm btn-warning">Редактировать страницу</button>
</div>
}
<h1>@siteMap.PageName</h1>

@Html.Raw(siteMap.Content)

@if (showLeftPart && showRightPart)
{
    <div class="table">
        <div class="row">
            <div class="col-sm-3">
                @foreach (var block in blocks.Where(x => x.Column == 1))
                {
                    @Html.Partial("_Block", block.Type, new ViewDataDictionary() {new KeyValuePair<string, object>("SiteMapNode", siteMap) })
                }
            </div>
            <div class="col-md-6">
                @Html.Partial("_News", 0)
            </div>
            <div class="col-md-3">
                @foreach (var block in blocks.Where(x => x.Column == 5))
                {
                    @Html.Partial("_Block", block.Type, new ViewDataDictionary() {new KeyValuePair<string, object>("SiteMapNode", siteMap) })
                }             
            </div>
        </div>
    </div>
}
else if(showLeftPart)
{
    <div>
            <div class="f_l">
                @foreach (var block in blocks.Where(x => x.Column == 1))
                {
                    @Html.Partial("_Block", block.Type, new ViewDataDictionary() {new KeyValuePair<string, object>("SiteMapNode", siteMap) })
                }
            </div>
            <div class="f_r" style="width: 100%; max-width: 770px;">
                @Html.Partial("_News", 0)
            </div>
    </div>    
}
else if (showRightPart)
{
    <div class="table">
        <div class="row">
            <div class="col-md-9">
                @Html.Partial("_News", 0)
            </div>
            <div class="col-md-2">
                @foreach (var block in blocks.Where(x => x.Column == 5))
                {
                    @Html.Partial("_Block", block.Type, new ViewDataDictionary() {new KeyValuePair<string, object>("SiteMapNode", siteMap) })
                }             
            </div>
        </div>
    </div>    
}
else
{
    <div>
        @Html.Partial("_News", 0)
    </div>    
}
